package com.tct.worktimeboard.controller;

import com.alibaba.fastjson.JSONObject;
import com.tct.worktimeboard.entity.GroupType;
import com.tct.worktimeboard.service.IGroupTypeService;
import com.tct.worktimeboard.util.JsonUtil;
import com.tct.worktimeboard.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Huhailong
 * @Description
 * @Date 2021/2/23.
 */
@RestController
@RequestMapping("/groupType")
public class GroupTypeController {

    @Autowired
    IGroupTypeService groupTypeService;

    /**
     * 获取群组分类
     * @param kindCode dept or bu
     * @return 返回群组信息
     */
    @GetMapping("/getGroupType")
    public JSONObject getGroupType(String kindCode){
        return groupTypeService.getGroupType(kindCode);
    }

    @PostMapping("/createGroupType")
    public JSONObject createGroupType(@RequestBody GroupType groupType){
        groupType.setCreateTime(TimeUtil.getDateTime());
        return JsonUtil.toJsonData(groupTypeService.addGroupType(groupType));
    }

    @GetMapping("/getGroupTypeList")
    public JSONObject getGroupTypeList(GroupType groupType){
        return groupTypeService.getGroupTypeList(groupType);
    }

    @PostMapping("/updateGroupType")
    public JSONObject updateGroupType(@RequestBody GroupType groupType){
        return JsonUtil.toJsonData(groupTypeService.updateById(groupType));
    }

    @PostMapping("/deleteGroupType")
    public JSONObject deleteGroupType(@RequestBody List<Long> ids){
        return JsonUtil.toJsonData(groupTypeService.removeByIds(ids));
    }
}
